/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package modele;

import java.sql.*;

/**
 *
 * @author sio
 */
public class Connect { //singleton

    //methodes
    
    private static Connection con = null;

    private static Connection open(){

            //Chargement du pilote
        
        try {
            Class.forName("org.postgresql.Driver");
        } catch (ClassNotFoundException e) {
            System.out.println("Pilote mal installé.." + e); //erreur SQL
        }

        try {
                
            //Connexion

            con = DriverManager.getConnection("jdbc:postgresql://lucie/medecin", "cbouchy", "Linux");
        } catch (SQLException e) {
            System.out.println("Erreur SQL :" + e); //affiche l'erreur SQL
        }

        return con;
    }

    public static Connection get(){
        if (con == null){
            con = Connect.open();
        }
        return con;
    }

    public static void close(){
        try{
            con.close();
        } catch (SQLException e){
            System.out.println("Erreur SQL :" + e);
        }
    }
}